//
// Created by xili on 2024/8/24 13:43.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int MOD = 1000000000 + 7;

    int countPairs(vector<int> &deliciousness) {
        int maxV = *max_element(deliciousness.begin(), deliciousness.end());
        int maxS = maxV * 2;
        unordered_map<int, int> ump;
        int ans = 0;
        for (auto &item: deliciousness) {
            for (int sum = 1; sum <= maxS; sum <<= 1) {
                int count = ump.count(sum - item) ? ump[sum - item] : 0;
                ans = (ans + count) % MOD;
            }
            ump[item]++;
        }
        return ans;
    }
};